Python Graphics by Bernard Korites
(7-5)
where C1 and C2 are constants and n is a parameter. n can be changed in the program. Noting that I=IA at ,
(7-6)
(7-7)
At = +2, ( = +1), I=IB,
(7-8)
(7-9)
With
(7-10)
Equation 7-10 is your intensity function, . You thus have three parameters with which to adjust I: IA, which regulates the intensity of the lightest areas; IB, which adjusts the darkest areas; and n, which adjusts the transition from light to dark. Higher values of n will produce a more rapid transition. Figure 7-14 shows curves for n=1, 2, 3, and 4. When n=1, the curve becomes linear. There are no definite values for n, IA, and IB; they should be adjusted by trial and error to give visually appealing results.
Regarding colors, the background shown in Figure 7-13 is 'midnightblue'. A good source for color samples is #https://matplotlib.org/examples/color/named_colors.html.
Listing 7-2 creates a sphere by plotting longitudes and latitudes as you did in Listing 6-4. In Listing 6-4, these were spaced six degrees apart. To carry out the shading in Listing 7-2, you will space the longitudes and latitudes closer together, two degrees apart. This creates 180x180=32,400 surface patches between the longitudes and latitudes. Assume each patch is flat. The intensity of color of each patch will depend on the angle between a local unit vector normal to the patch and the light source unit vector at each point on the surface. This will then be used to control the relative r,g,b contributions to the color mix. As before, you establish this relation by taking the dot product . at each point is determined quite simply by obtaining a vector from the sphereâs center to the point in question on the sphereâs surface and then dividing by the sphereâs radius, rs. For example, suppose you are at a point p on the sphereâs surface with coordinates xp,yp,zp. A vector Vp from the sphereâs center at xc,yc,zc to p is